<template>
	<view class="body">
		<!-- tabber切换 -->
		<swiperTabHead :tabBars="tabBars" :tabIndex="tabIndex" @tabtap="tabtap" scrollItemStyle="width:33%;" scrollStyle="border-bottom:0;">
		</swiperTabHead>

		<!-- 好友列表 -->
		<!-- <block v-for="(item, index) in list" :key="index">
			
		</block> -->

		<view class="uni-tab-bar">
			<swiper :style="{height:swiperHeight+'px'}" :current="tabIndex" @change="swiperChange">
				<swiper-item v-for="(items, index) in newlist" :key="index">
					<scroll-view scroll-y class="list" @scrolltolower="loadmore(index)">
						<template v-if="items.list.length > 0">
							<!-- 图文列表 -->
							<block v-for="(item, index1) in items.list" :key="index1">
								<user-list :item="item" :index="index1"></user-list>
							</block>
							<!-- 上拉加载 -->
							<loadMore :loadtext="items.loadtext"></loadMore>
						</template>
						<template v-else>
							<!-- 无内容 -->
							<noThing></noThing>
						</template>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>

	</view>
</template>

<script>
	import swiperTabHead from '../../components/common/swiper-tab-head.vue';
	import userList from "../../components/user-list/user-list.vue";
	import loadMore from '../../components/common/load-more.vue';
	import noThing from '../../components/common/no-thing.vue';
	export default {
		components: {
			swiperTabHead,
			userList,
			loadMore,
			noThing
		},
		data() {
			return {
				swiperHeight: 500,
				tabBars: [{
						name: "互关",
						id: "huguan",
						num: 20
					},
					{
						name: "关注",
						id: "guanzhu",
						num: 10
					},
					{
						name: "粉丝",
						id: "fensi",
						num: 3
					},
				],
				tabIndex: 0,
				newlist: [{
						loadtext: "上拉加载更多",
						list: [{
								userpic: "../../static/demo/userpic/14.jpg",
								username: "昵称",
								age: 20,
								sex: 0,
								isguanzhu: false
							},
							{
								userpic: "../../static/demo/userpic/12.jpg",
								username: "昵称2",
								age: 23,
								sex: 1,
								isguanzhu: true
							},{
								userpic: "../../static/demo/userpic/14.jpg",
								username: "昵称",
								age: 20,
								sex: 0,
								isguanzhu: false
							},
							{
								userpic: "../../static/demo/userpic/12.jpg",
								username: "昵称2",
								age: 23,
								sex: 1,
								isguanzhu: true
							},{
								userpic: "../../static/demo/userpic/14.jpg",
								username: "昵称",
								age: 20,
								sex: 0,
								isguanzhu: false
							},
							{
								userpic: "../../static/demo/userpic/12.jpg",
								username: "昵称2",
								age: 23,
								sex: 1,
								isguanzhu: true
							},{
								userpic: "../../static/demo/userpic/14.jpg",
								username: "昵称",
								age: 20,
								sex: 0,
								isguanzhu: false
							},
							{
								userpic: "../../static/demo/userpic/12.jpg",
								username: "昵称2",
								age: 23,
								sex: 1,
								isguanzhu: true
							},{
								userpic: "../../static/demo/userpic/14.jpg",
								username: "昵称",
								age: 20,
								sex: 0,
								isguanzhu: false
							},
							{
								userpic: "../../static/demo/userpic/12.jpg",
								username: "昵称2",
								age: 23,
								sex: 1,
								isguanzhu: true
							}
						]
					},
					{
						loadtext: "上拉加载更多",
						list: [{
								userpic: "../../static/demo/userpic/15.jpg",
								username: "昵称",
								age: 20,
								sex: 0,
								isguanzhu: false
							},
							{
								userpic: "../../static/demo/userpic/16.jpg",
								username: "昵称2",
								age: 23,
								sex: 1,
								isguanzhu: true
							}
						]
					},
					{
						loadtext: "上拉加载更多",
						list: [{
								userpic: "../../static/demo/userpic/11.jpg",
								username: "昵称",
								age: 20,
								sex: 0,
								isguanzhu: false
							},
							{
								userpic: "../../static/demo/userpic/11.jpg",
								username: "昵称2",
								age: 23,
								sex: 1,
								isguanzhu: true
							}
						]
					}
				]
			}
		},
		onLoad() {
			uni.getSystemInfo({
				success: (res) => {
					let height = res.windowHeight - uni.upx2px(100);
					// console.log(height);
					this.swiperHeight = height;
				}
			})
		},
		onNavigationBarButtonTap(e) {
			console.log(e.index);
			if (e.index == 0) {
				uni.navigateBack({});
			}
		},
		methods: {
			loadmore(index){
				if(this.newlist[index].loadtext != "上拉加载更多") {return;}
				this.newlist[index].loadtext = "加载中";
				setTimeout(()=>{
					//获取完成
					let obj = {
								userpic: "../../static/demo/userpic/11.jpg",
								username: "昵称2",
								age: 23,
								sex: 1,
								isguanzhu: true
							};
					this.newlist[index].list.push(obj);
					this.newlist[index].loadtext = "上拉加载更多";
				},1000)
			},
			//tabbar点击事件
			tabtap(index) {
				this.tabIndex = index;
			},
			//swiper滑动事件
			swiperChange(e) {
				// console.log(JSON.stringify(e.detail));
				this.tabIndex = e.detail.current;
			}
		}
	}
</script>

<style>



</style>
